/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package managedbean.Workspace;

import java.util.ArrayList;
import java.util.Collection;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import merlion.common.entity.AuditLog;
import merlion.common.entity.SystemUserAccount;
import merlion.common.session.stateless.LogTrackingSessionBeanLocal;

/**
 *
 * @author Zhang Ying
 */
@ManagedBean
@ViewScoped
public class LogManagerBean {
    
    @EJB
    private LogTrackingSessionBeanLocal auditLogManager;
    // for log in logs view
    private Collection<AuditLog> allLoggingLogs = new ArrayList<AuditLog>();

    /** Creates a new instance of LogManagerBean */
    public LogManagerBean() {
    }
    
    public String getUsernameByLogId(Long logId){
        return getAccountByLogId(logId).getUsername();
    }
    
    public String getStaffNameByLogId(Long logId){
        return getAccountByLogId(logId).getStaff().getFullName();
    }
    
    public SystemUserAccount getAccountByLogId(Long logId){
        return auditLogManager.getAccountByLogId(logId);
    }

    public Collection<AuditLog> getAllLoggingLogs() {
        allLoggingLogs = auditLogManager.getAllLoggingLogs();
        return allLoggingLogs;
    }

    public void setAllLoggingLogs(Collection<AuditLog> allLoggingLogs) {
        this.allLoggingLogs = allLoggingLogs;
    }

    public boolean isFirstLoggedIn(Long accId) {
        if (auditLogManager.getLastLoginTimeString(accId) != null){
            return false;
        }else{
            return true;
        }
    }

    // home page
    public String getLastLoginTimeString(Long accId){
        return auditLogManager.getLastLoginTimeString(accId);
    }

}
